<template>
	<view class="container">
		
		
		<!-- 头部 -->
		<tui-navigation-bar class="navigationBar" :isOpacity="false" >
			<view class="tui-content-box">
				<view>
					<tui-icon name="arrowleft" color="#ffffff" @click="backTo"></tui-icon>
				</view>
				<view class="tui-content-tit">
					<view>我的发布</view>
				</view>
			</view>
		</tui-navigation-bar>
		
		
		
		<view class="user-section">
			<view class="bg">
				<image class="bg_img" src="../../static/img/yuncang/yuncang.png"></image>
			</view>
			<view class="user-info-box">
				<view class="left_box">
					<view class="portrait-box">
						<image class="portrait" :src="userInfo.avatar"></image>
					</view>
					<view class="user-box">
						<view class="info-box">
							<text class="username">{{userInfo.nickname || userInfo.username}}</text>
							<text class="partner" v-show="userInfo.userLevel == '0' || userInfo.userLevel == '1' || userInfo.userLevel == '2' || userInfo.userLevel == '3'">{{userInfo.userLevel == '1' ? '零售商' : userInfo.userLevel == '2' ? '代理商' : userInfo.userLevel == '3' ? '合伙人' : '普通用户'}}</text>
						</view>
						<view class="invitation">
							<text class="Code">素材 : {{total}}</text>
							<text class="num">视频 : {{videoCount}}</text>
						</view>
					</view>
				</view>
				<view class="right_box" @click="navTo()">
					<image src="../../static/img/me/my_center_arrows.png" mode=""></image>
				</view>
			</view>
		</view>

		<view class="contents">
			<view class="navbar">
				<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{current: tabCurrentIndex == index}"
				 @click="tabClick(index)">
					{{item.text}}
				</view>
			</view>


			<!-- 订单列表 -->
			<view v-for="(item,index) in orderList" :key="index" class="order-item">

				<view class="i-top b-b">
					<text class="time">{{item.addTime}}</text>
					<text class="state" :style="{color: item.stateTipColor}">{{item.auditStatus == '2' ? '发布成功' : item.auditStatus == '1' ? '审核中' : ''}}</text>
				</view>

				<view class="goods-box-single" @click="toDetail(goodsIndex)">
					<image class="goods-img" :src="item.avatar" mode="aspectFill"></image>
					<view class="right">
						<text class="title">{{item.content}}</text>
						<view style="padding-top: 10px;">
							<text class="countmax" v-if="item.imgList.length">共{{item.imgList.length}}张</text>
						</view>
					</view>
				</view>

			</view>

			<!-- 空白页 -->
			<view class="empty-content" v-if="orderList.length === 0">
				<image class="empty-image" src="../../static/img/yuncang/cloud_no_order.png" mode="aspectFit"></image>
				
				<view class="empty-text">暂无相关订单</view>
				
			</view>


			<!--加载loadding-->
			<tui-loadmore v-if="loadding" :index="total" type="primary"></tui-loadmore>
			<tui-nomore v-if="!pullUpOn"></tui-nomore>
			<!--加载loadding-->


		</view>



	</view>
</template>
<script>
	import empty from "@/components/empty";

	export default {
		components: {
			empty
		},
		data() {
			return {
				tabCurrentIndex: 0,
				navList: [
					{
						state: "",
						text: '全部发布',
					},
					{
						state: 1,
						text: '待审核',
					},
					{
						state: 0,
						text: '审核通过',
					},
				],
				total: "", //一共多少条
				limit: "10", //一页十条
				page: "1", //几页
				pages: "", //一共多少页
				loadding: false, //加载
				pullUpOn: true, //没有数据
				orderList: [],
				videoCount: "",
				materialTotal: "",
				userInfo: "",
			}
		},

		onLoad() {
			this.loadData()
			//获取用户信息
			this.userInfo = uni.getStorageSync("userInfo")
		},
		// 下拉刷新
		onPullDownRefresh: function() {
			this.page = 1;
			this.pullUpOn = true;
			this.loadding = false;
			this.loadData();
			uni.stopPullDownRefresh();
			this.tui.toast("刷新成功")
		},

		// 上拉加载
		onReachBottom: function() {debugger
			console.log(this.page)
			if (!this.pullUpOn) {
				return;
			}
			this.loadding = true;
			if (this.page == this.pages) {
				this.loadding = false;
				this.pullUpOn = false
			} else {
				++this.page;
				this.loadData();
				this.loadding = false
			}
		},
		methods: {
			backTo(){
				uni.navigateBack({
					
				})
			},
			
			
			//获取订单列表
			loadData() {
				let _this = this;

				_this.tui.request('/app/material/myMaterial', 'GET', {}, false, false, false, )
					.then(res => {
						if (res.errno == 0) {
							2
							_this.navList.orderList = res.data.list
							_this.orderList = res.data.list
							_this.videoCount = res.data.videoCount
							_this.total = res.data.total
							_this.materialTotal = res.data.materialTotal
						} else {
							console.log(res)
							_this.tui.toast(res.errmsg)
						}
					}).catch(err => {
						console.log(err)
					})

			},


			//顶部tab点击
			tabClick(index) {
				console.log(index)
				this.tabCurrentIndex = index
				let auditStatus = "";
				if (index == 0) {
					
					
					this.tui.request('/app/material/myMaterial', 'GET', {}, false, false, false, )
						.then(res => {
							if (res.errno == 0) {
								this.navList.orderList = res.data.list
								this.orderList = res.data.list
								this.videoCount = res.data.videoCount
								this.total = res.data.total
								this.materialTotal = res.data.materialTotal
							} else {
								console.log(res)
								this.tui.toast(res.errmsg)
							}
						}).catch(err => {
							console.log(err)
						})
					
					
					
					
					
				} else if (index == 1) {
					auditStatus = 1;
					
					this.tui.request('/app/material/myMaterial', 'GET', {
							auditStatus: auditStatus
						}, false, false, false, )
						.then(res => {
							if (res.errno == 0) {
								this.navList.orderList = res.data.list
								this.orderList = res.data.list
								this.videoCount = res.data.videoCount
								this.total = res.data.total
								this.materialTotal = res.data.materialTotal
							} else {
								console.log(res)
								this.tui.toast(res.errmsg)
							}
						}).catch(err => {
							console.log(err)
						})
					
					
				} else if (index == 2) {
					auditStatus = 2;
					
					
					this.tui.request('/app/material/myMaterial', 'GET', {
							auditStatus: auditStatus
						}, false, false, false, )
						.then(res => {
							if (res.errno == 0) {
								this.navList.orderList = res.data.list
								this.orderList = res.data.list
								this.videoCount = res.data.videoCount
								this.total = res.data.total
								this.materialTotal = res.data.materialTotal
							} else {
								console.log(res)
								this.tui.toast(res.errmsg)
							}
						}).catch(err => {
							console.log(err)
						})
					
				}

				
			},

			// 返回
			navTo() {
				uni.navigateBack({

				})
			},
			// 去详情
			toDetail(row) {
				uni.reLaunch({
					url: ''
				})
			}
		}
	}
</script>
<style lang='scss'>
	page {
		height: 100%;
	}
	/*navigation-bar*/
	.navigationBar{
		background: url(../../static/img/yuncang/yuncang.png) no-repeat;
		background-size: 100% 600upx;
	}
	.tui-content-box {
		width: 100%;
		height: 44px;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		
	}
		
	.tui-content-tit{
		width: 100%;
		height: 56upx;
		margin: 0 100rpx;
		color: #ffffff;
		font-size: 18px;
		padding: 0 12px;
		text-align: center;
		margin-left: 46rpx;
	}
	
	.tui-search-box {
		width: 100%;
		height: 56upx;
		margin: 0 100rpx;
		border-radius: 18px;
		font-size: 14px;
		padding: 0 12px;
		box-sizing: border-box;
		color: #bfbfbf;
		display: flex;
		align-items: center;
		background-color: rgba(255, 255, 255, .2);
	}
	
	.tui-search-text {
		color: #ffffff;
		padding-left: 10rpx;
	}

	
	
	
	
	/* 空页面 */
	.empty-content {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding-top: 200upx;
		
		&-image {
			width: 200upx;
			height: 200upx;
		}
	}

	.empty-image{
		width: 200upx;
		height: 200upx;
	}
	.empty-text{
		font-size: 18px;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: rgba(110,96,158,1);
		line-height: 40px;
	}
	
	
	
	
	
	
	
	.container {
		background: #FAFAFA;
		height: 100%;
	}

	.user-section {
		padding: 200upx 30upx 0;
		position: relative;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			filter: blur(1px);
			/* opacity: .7; */

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.user-info-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		z-index: 1;
		padding-bottom: 26upx;

		.left_box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			z-index: 1;

			.portrait {
				width: 130upx;
				height: 130upx;
				border: 5upx solid #fff;
				border-radius: 50%;
			}

			.info-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			.username {
				margin-left: 20upx;
				font-size: 32upx;
				font-family: Source Han Sans CN;
				font-weight: 800;
				color: rgba(255, 255, 255, 1);
			}

			.partner {
				background: rgba(255, 255, 255, 1);
				border-radius: 16px;
				margin-left: 20upx;
				font-size: 12px;
				padding: 2px 10px 2px 10px;
			}

			.invitation {
				font-size: 24upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: rgba(255, 255, 255, 1);
				line-height: 29px;
				margin-left: 20upx;

				.Code {
					padding-right: 5upx;
				}

				.num {
					padding-left: 5upx;
				}
			}
		}

		.right_box {

			image {
				width: 23upx;
				height: 32upx;
			}
		}

	}




	.swiper-box {
		height: calc(100% - 40px);
	}

	.list-scroll-content {
		height: 100%;
	}

	.navbar {
		display: flex;
		height: 40px;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, .06);
		position: relative;
		z-index: 10;

		.nav-item {
			/* flex: 1; */
			width: 15%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 12px;
			color: #808080;
			position: relative;

			&.current {
				color: #333333;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 12px;
					-webkit-transform: translateX(-50%);
					transform: translateX(-50%);
					width: 45px;
					height: 0px;
					border-bottom: 5px solid #6E609E;
					opacity: .8;
					border-radius: 5px;
				}
			}
		}
	}

	.uni-swiper-item {
		height: auto;
	}

	.order-item {
		display: flex;
		flex-direction: column;
		padding-left: 30upx;
		background: #fff;
		margin-top: 16upx;

		.i-top {
			display: flex;
			align-items: center;
			height: 80upx;
			padding-right: 30upx;
			font-size: $font-base;
			color: #333333;
			position: relative;

			.time {
				flex: 1;
				color: #333333;
			}

			.state {
				color: #FF0000;
			}

			.del-btn {
				padding: 10upx 0 10upx 36upx;
				font-size: $font-lg;
				color: $font-color-light;
				position: relative;

				&:after {
					content: '';
					width: 0;
					height: 30upx;
					border-left: 1px solid $border-color-dark;
					position: absolute;
					left: 20upx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}

		/* 多条商品 */
		.goods-box {
			height: 160upx;
			padding: 20upx 0;
			white-space: nowrap;

			.goods-item {
				width: 120upx;
				height: 120upx;
				display: inline-block;
				margin-right: 24upx;
			}

			.goods-img {
				display: block;
				width: 100%;
				height: 100%;
			}
		}

		/* 单条商品 */
		.goods-box-single {
			display: flex;
			padding: 20upx 0;

			.goods-img {
				display: block;
				width: 120upx;
				height: 120upx;
			}

			.right {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 30upx 0 24upx;
				overflow: hidden;

				.title {
					font-size: $font-base + 2upx;
					color: $font-color-dark;
					line-height: 19px;
				}

				.countmax {
					font-size: $font-base + 2upx;
					color: $font-color-dark;
				}

				.attr-box {
					font-size: $font-sm + 2upx;
					color: $font-color-light;
					padding: 10upx 12upx;
				}

				.number {
					font-size: 12px;
					color: #999999;
					text-align: right;

					&:before {
						content: '￥';
						font-size: $font-sm;
						margin: 0 2upx 0 8upx;
					}
				}

				.price {
					font-size: $font-base + 2upx;
					color: #6E609E;
					text-align: right;

					&:before {
						content: '￥';
						font-size: $font-sm;
						margin: 0 2upx 0 8upx;
					}
				}
			}
		}

		.price-box {
			display: flex;
			justify-content: flex-end;
			align-items: baseline;
			padding: 20upx 30upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;

			.num {
				margin: 0 8upx;
				color: $font-color-dark;
			}

			.price {
				font-size: $font-lg;
				color: $font-color-dark;

				&:before {
					content: '￥';
					font-size: $font-sm;
					margin: 0 2upx 0 8upx;
				}
			}
		}

		.action-box {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			height: 100upx;
			position: relative;
			padding-right: 30upx;
		}

		.action-btn {
			width: 160upx;
			height: 60upx;
			margin: 0;
			margin-left: 24upx;
			padding: 0;
			text-align: center;
			line-height: 60upx;
			font-size: $font-sm + 2upx;
			color: $font-color-dark;
			background: #fff;
			border-radius: 100px;

			&:after {
				border-radius: 100px;
			}

			// &.recom {
			// 	// background: #fff9f9;
			// 	color: $base-color;

			// 	&:after {
			// 		border-color: #f7bcc8;
			// 	}
			// }
		}
	}


	/* load-more */
	.uni-load-more {
		display: flex;
		flex-direction: row;
		height: 80upx;
		align-items: center;
		justify-content: center
	}

	.uni-load-more__text {
		font-size: 28upx;
		color: #999
	}

	.uni-load-more__img {
		height: 24px;
		width: 24px;
		margin-right: 10px
	}

	.uni-load-more__img>view {
		position: absolute
	}

	.uni-load-more__img>view view {
		width: 6px;
		height: 2px;
		border-top-left-radius: 1px;
		border-bottom-left-radius: 1px;
		background: #999;
		position: absolute;
		opacity: .2;
		transform-origin: 50%;
		animation: load 1.56s ease infinite
	}

	.uni-load-more__img>view view:nth-child(1) {
		transform: rotate(90deg);
		top: 2px;
		left: 9px
	}

	.uni-load-more__img>view view:nth-child(2) {
		transform: rotate(180deg);
		top: 11px;
		right: 0
	}

	.uni-load-more__img>view view:nth-child(3) {
		transform: rotate(270deg);
		bottom: 2px;
		left: 9px
	}

	.uni-load-more__img>view view:nth-child(4) {
		top: 11px;
		left: 0
	}

	.load1,
	.load2,
	.load3 {
		height: 24px;
		width: 24px
	}

	.load2 {
		transform: rotate(30deg)
	}

	.load3 {
		transform: rotate(60deg)
	}

	.load1 view:nth-child(1) {
		animation-delay: 0s
	}

	.load2 view:nth-child(1) {
		animation-delay: .13s
	}

	.load3 view:nth-child(1) {
		animation-delay: .26s
	}

	.load1 view:nth-child(2) {
		animation-delay: .39s
	}

	.load2 view:nth-child(2) {
		animation-delay: .52s
	}

	.load3 view:nth-child(2) {
		animation-delay: .65s
	}

	.load1 view:nth-child(3) {
		animation-delay: .78s
	}

	.load2 view:nth-child(3) {
		animation-delay: .91s
	}

	.load3 view:nth-child(3) {
		animation-delay: 1.04s
	}

	.load1 view:nth-child(4) {
		animation-delay: 1.17s
	}

	.load2 view:nth-child(4) {
		animation-delay: 1.3s
	}

	.load3 view:nth-child(4) {
		animation-delay: 1.43s
	}

	@-webkit-keyframes load {
		0% {
			opacity: 1
		}

		100% {
			opacity: .2
		}
	}
</style>
